/*
 * Copyright 2019 Xilinx, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "lookup_math.h"
#include <math.h>

void init_sin_table(din1_t sin_table[256])
{
   int i;
   for (i = 0; i < 256; i++) {
      dint_t real_val = sin(M_PI * (dint_t)(i - 128) / 256.0);
      sin_table[i] = (din1_t)(32768.0 * real_val);
   }
}

dout_t lookup_math(din1_t inval, din2_t idx)
{
   short sin_table[256];
   init_sin_table(sin_table);
   return (int)inval * (int)sin_table[idx];
}
